﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Scriptor.Presentation.Enumerator;

namespace Scriptor.Presentation.Templates
{
    public class EnumTemplate
    {
        List<string> gUsing { get; set; }
        public StringBuilder clausulaUsingFormatada { get; set; }

        List<string> gEnum { get; set; }
        public StringBuilder enumFormatado { get; set; }

        List<string> gEnumItem { get; set; }
        public StringBuilder EnumItemFormatado { get; set; }

        public string strUsing(Enums.OrigemEnum origem)
        {
            gUsing = new List<string>();

            gUsing.Add("using System;");
            gUsing.Add("using System.Collections.Generic;");
            gUsing.Add("using System.Linq;");
            gUsing.Add("using System.Text;");

            if (origem == Enums.OrigemEnum.DataContract)
                gUsing.Add("using System.Runtime.Serialization;");
            else
                if (origem == Enums.OrigemEnum.BusinessEntity)
                    gUsing.Add("using Sinacor.Infra.Service.Common;");

            clausulaUsingFormatada = new StringBuilder();

            foreach (string str in gUsing)
            {
                clausulaUsingFormatada.Append(str);
                clausulaUsingFormatada.Append(Environment.NewLine);
            }

            return clausulaUsingFormatada.ToString();
        }

        public string strEnum(string pNameSpace, string pEnumName)
        {
            gEnum = new List<string>();

            gEnum.Add("namespace " + pNameSpace);
            gEnum.Add("{");
            gEnum.Add("\tpublic enum " + pEnumName);
            gEnum.Add("\t{");
            gEnum.Add("@@enum-body");
            gEnum.Add("\t}");
            gEnum.Add("}");

            enumFormatado = new StringBuilder();

            foreach (string str in gEnum)
            {
                enumFormatado.Append(str);
                enumFormatado.Append(Environment.NewLine);
            }

            return enumFormatado.ToString();
        }

        public string strEnumItem(string enumItemName, Enums.OrigemEnum origem, bool showDecorators)
        {
            gEnumItem = new List<string>();

            if (origem == Enums.OrigemEnum.DataContract)
            {
                if (showDecorators)
                {
                    gEnumItem.Add("\t\t[EnumMember]");
                }
            }

            gEnumItem.Add("\t\t" + enumItemName + ",");

            EnumItemFormatado = new StringBuilder();

            foreach (string str in gEnumItem)
            {
                EnumItemFormatado.Append(str);
                EnumItemFormatado.Append(Environment.NewLine);
            }

            EnumItemFormatado.Append(Environment.NewLine);

            return EnumItemFormatado.ToString();
        }

        public string AppendEnumItem(string pClassScope, StringBuilder stb)
        {
            return pClassScope.ToString().Replace("@@enum-body",
                stb.ToString().Substring(0, stb.ToString().LastIndexOf(',')) + Environment.NewLine);
        }
    }
}